﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using transportsystem.BUS;
using transportsystem.DTO;

namespace transportsystem
{
    public partial class frmMain : Form
    {
        private DataTable dt;
        private PhanQuyen pq;
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            frmLogin frm = new frmLogin();
            DialogResult dr = frm.ShowDialog();
            if (dr == DialogResult.OK)
            {
                MessageBox.Show("Đăng nhập thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                stslLogInfo.Text = "Xin chào " + frmLogin.Nhanvien.Tennv;
                //toolStripStatusLabel1.Text = "Xin chào " + DangNhapForm.Employee.Name;
                this.layQuyenChoNhanVien();
            }
        }
        public void layQuyenChoNhanVien()
        {
            int macv = frmLogin.Nhanvien.Macv;
            dt = ChucVuBUS.layChucVuTheoMa(macv);
            if (dt != null && dt.Rows.Count == 1)
            {
                ChucVu cv = new ChucVu();
                cv.Macv = int.Parse(dt.Rows[0]["macv"].ToString());
                cv.Maphanquyen = int.Parse(dt.Rows[0]["maphanquyen"].ToString());

                DataTable d = PhanQuyenBUS.layPhanQuyenTheoMa(cv.Maphanquyen);
                if (d != null && d.Rows.Count == 1)
                {
                    pq = new PhanQuyen();
                    pq.Maphanquyen = int.Parse(d.Rows[0]["maphanquyen"].ToString());
                    pq.Capnhattaikhoan = int.Parse(d.Rows[0]["capnhattaikhoan"].ToString());
                    pq.Dangnhap = int.Parse(d.Rows[0]["dangnhap"].ToString());
                    pq.Dangxuat = int.Parse(d.Rows[0]["dangxuat"].ToString());
                    pq.Tracuu = int.Parse(d.Rows[0]["tracuu"].ToString());
                    pq.Thaotacdatve = int.Parse(d.Rows[0]["thaotacdatve"].ToString());
                    pq.Capnhatthongtinve = int.Parse(d.Rows[0]["capnhatthongtinve"].ToString());
                    pq.Thaotachuyve = int.Parse(d.Rows[0]["thaotachuyve"].ToString());
                    pq.Dieuphoichuyenxe = int.Parse(d.Rows[0]["dieuphoichuyenxe"].ToString());
                    pq.Quanlydaily = int.Parse(d.Rows[0]["quanlydaily"].ToString());
                    pq.Quanlydatve = int.Parse(d.Rows[0]["quanlydatve"].ToString());
                    pq.Quanlykhachhang = int.Parse(d.Rows[0]["quanlykhachhang"].ToString());
                    pq.Tinhchiphi = int.Parse(d.Rows[0]["tinhchiphi"].ToString());
                    pq.Thongkenhanvien = int.Parse(d.Rows[0]["thongkenhanvien"].ToString());
                    pq.Thongkedoanhthu = int.Parse(d.Rows[0]["thongkedoanhthu"].ToString());
                    pq.Baocaodoanhthu = int.Parse(d.Rows[0]["baocaodoanhthu"].ToString());
                    pq.Quanlyhoadon= int.Parse(d.Rows[0]["quanlyhoadon"].ToString());
                    pq.Quanlykhohang = int.Parse(d.Rows[0]["quanlykhohang"].ToString());
                    pq.Quanlylichtrinh = int.Parse(d.Rows[0]["quanlylichtrinh"].ToString());
                    pq.Quanlynguoidung = int.Parse(d.Rows[0]["quanlynguoidung"].ToString());
                    pq.Quanlynhanvien= int.Parse(d.Rows[0]["quanlynhanvien"].ToString());
                    pq.Quanlytuyenxe = int.Parse(d.Rows[0]["quanlytuyenxe"].ToString());
                    pq.Quanlyxe= int.Parse(d.Rows[0]["quanlyxe"].ToString());
                    this.PhanQuyen(pq);
                }
            }

        }

        public void PhanQuyen(PhanQuyen P)
        {
            if (P.Maphanquyen == 1)
            {
                mnuLogout.Enabled = true;
                mnuTacVu.Enabled = true;
                //....
            }
            if (P.Maphanquyen == 2)
            {
                //....
            }
        }

        private void tuyếnXeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTuyen frm = new frmTuyen();
            frm.MdiParent = this;
            frm.Show();
        }

        private void mnuUsers_Click(object sender, EventArgs e)
        {
            frmNhanVien frm = new frmNhanVien();
            frm.MdiParent = this;
            frm.Show();
        }
    }
}
